package cn.edu.ecut.exception;

/**
 * 当 return 遇到 try...catch...finally 语句时，仍然是 finally 先执行后再执行 return
 */
public class ExceptionHandlingTestD {
	
	public static void main(String[] args) {
		System.out.println( "main begin ..." );
		int x = test2();
		System.out.println( x );
		System.out.println( "main end ." );
	}
	
	@SuppressWarnings("finally")
	public static int test1(){
		try {
			System.out.println( 100 / 0 );
			System.out.println( "- - - try - - -" );
			return 1  ; // try
		} catch( Exception cause ) {
			System.out.println( "- - - catch - - -" );
			return -1 ; // catch
		} finally {
			System.out.println( "- - - finally - - -" );
			return 0 ; // finally
		}
	}
	
	@SuppressWarnings("finally")
	public static int test2(){
		int a = 100 ;
		try {
			System.out.println( "- - - try - - -" );
			return a + 10 ;
		} catch( Exception cause ) {
			System.out.println( "- - - catch - - -" );
			return a - 10 ;
		} finally {
			System.out.println( "- - - finally - - -" );
			return ++a ;
		}
	}

}
